<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>echarts地图</title>
    <script src="../js/data.js"></script>
    <script src="../js/echarts.min.js"></script>
    <script src="../js/jquery.min.js"></script>
</head>

<body>
<div class="viewport" id="home">
    <div class="echarts" id="echarts"></div>
</div>
</body>
<script>
    // 获取数据
    function getData() {
        $.get('../js/data.json', function (data) {
            getEcharts(data)
        });
    }

    // 渲染echarts
    function getEcharts(data) {
        var chartDom = document.getElementById('echarts');
        var myChart = echarts.init(chartDom);
        var nameMap = '地图数据';
        var geoCoordMap = {};
        var dataList = []
        echarts.registerMap(nameMap, data);
        /*获取地图数据*/
        myChart.showLoading();
        var mapFeatures = echarts.getMap(nameMap).geoJson.features;
        myChart.hideLoading();
        mapFeatures.forEach(function (v) {
            dataList.push({
                name: v.properties.name,
                value: Math.random() * 1000
            });
            // 地区名称
            var name = v.properties.name;
            // 地区经纬度
            geoCoordMap[name] = v.properties.center;
        });
        var serverdata = [
            { // 地图块的相关信息
                type: 'map',
                name: '全区工程数量分布',
                map: nameMap,
                zoom: 1.2,
                itemStyle: {
                    normal: {
                        borderColor: 'rgba(14, 34, 150, 1.00)',
                        borderWidth: 1,
                        areaColor: '#416ef8'
                    },
                    emphasis: {
                        areaColor: '#416ef8',
                        borderWidth: 0,
                        label: {
                            show: true,
                            color: '#fff'
                        },
                    }
                },
                select: {
                    label: {
                        show: true,
                        color: '#fff',
                        normal: {
                            show: true,
                            textStyle: {
                                fontSize: 14,
                                fontWeight: 400,
                                color: '#fff'
                            }
                        },
                        emphasis: {
                            textStyle: {
                                fontSize: 14,
                                fontWeight: 400,
                                color: '#fff'
                            }
                        }
                    },
                    itemStyle: {
                        areaColor: '#416ef8',
                        borderWidth: 0,
                    }
                },
                label: {
                    show: true,
                    normal: {
                        show: true,
                        textStyle: {
                            fontSize: 14,
                            fontWeight: 400,
                            color: '#fff'
                        }
                    },
                    emphasis: {
                        textStyle: {
                            fontSize: 14,
                            fontWeight: 400,
                            color: '#fff'
                        }
                    }
                },
                data: dataList
            },
            {
                type: 'effectScatter',
                coordinateSystem: 'geo',
                z: 5,
                data: [],
                symbolSize: 14,
                itemStyle: {
                    normal: {
                        borderColor: 'rgba(14, 34, 150, 1.00)',
                        borderWidth: 1,
                        areaColor: '#416ef8'
                    },
                    emphasis: {
                        areaColor: '#416ef8',
                        borderWidth: 0,
                        label: {
                            show: true,
                            color: '#fff',
                            normal: {
                                show: true,
                                textStyle: {
                                    fontSize: 14,
                                    fontWeight: 400,
                                    color: '#fff'
                                }
                            },
                            emphasis: {
                                show: true,
                                textStyle: {
                                    fontSize: 14,
                                    fontWeight: 400,
                                    color: '#fff'
                                }
                            }
                        },
                    }
                }
            },
        ]
        var optionMap = {
            tooltip: {
                trigger: 'item',
                show: true,
            },
            visualMap: [{
                min: 0,
                max: 1000,
                show: true,
                right: 20,
                bottom: 0,
                realtime: true,
                calculable: true,
                seriesIndex: [0],
                inRange: {
                    color: ['#015afe', '#0160ff', '#0079ff', '#0b97ff', '#14a9ff', '#21c8ff'].reverse()
                }
            }],
            geo: {
                map: nameMap,
                show: true,
                roam: false, //是否允许缩放
                zoom: 1.2, //默认显示级别
                itemStyle: {
                    normal: {
                        areaColor: '#3391f8',
                        shadowColor: '#3391f8',
                        shadowBlur: 1,
                        shadowOffsetX: 0,
                        shadowOffsetY: 8,
                    }
                },
                label: {
                    normal: {
                        show: false
                    },
                    emphasis: {
                        show: false
                    }
                }
            },
            series: serverdata
        };
        myChart.clear()
        myChart.resize()
        myChart.setOption(optionMap, true);
    }

    if (window.location.origin == 'file://') {
        setTimeout(() => {
            getEcharts(gdMap)
        }, 100)
    } else {
        getData()
    }
</script>
</html>
<style>
    html, body {
        padding: 0;
        margin: 0;
    }

    #home {
        width: 100%;
        height: 100%;
        background: #0d1551;
        position: fixed;
    }

    .echarts {
        width: 100%;
        height: 100%;
        background: #0d1551;
        position: fixed;
    }

    .info {
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 10;
        color: red;
    }

    .links {
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 10;

    }

    .links a {
        text-decoration: none;
        color: #fff;
    }
</style>
